package com.zhongjian.technologycal.mall.activity.personal.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.widget.TextView;
import com.zhongjian.technologycal.mall.R;
import com.zhongjian.technologycal.mall.adapter.PhotoAdapter;
import com.zhongjian.technologycal.mall.base.BaseActivity;
import com.zhongjian.technologycal.mall.interfacemall.RecyclerItemClickListener;
import com.zhongjian.technologycal.mall.utils.LogUtils;
import com.zhongjian.technologycal.mall.utils.StatusBarUtil;
import com.zhongjian.technologycal.mall.view.RatingBarView;

import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by wei on 2017/12/14.
 * 评价页面的功能实现
 *
 */

public class CommentActivity extends BaseActivity {
    @BindView(R.id.tv_main_title)
    TextView tv_main_title;
    private ArrayList<String> selectedPhotos = new ArrayList<>();
    private PhotoAdapter photoAdapter;
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;
    @BindView(R.id.rb)
    RatingBarView ratingBarView;
    @BindView(R.id.comment_tv_des_status)
    TextView comment_tv_des_status;


    @Override
    protected void beforeInit() {
        super.beforeInit();
//        StatusBarUtil.setColorNoTranslucent(this, getResources().getColor(R.color.border_color));
//        StatusBarUtil.setMiuiStatusBarDarkMode(this, true);
    }
    @Override
    public void initPresenter() {

    }
    /**
     * 初始化数据
     * @param savedInstanceState
     */
    @Override
    protected void initView(Bundle savedInstanceState) {
        tv_main_title.setText("发表评论");
        photoAdapter = new PhotoAdapter(CommentActivity.this,selectedPhotos);
        recyclerView.setLayoutManager(new StaggeredGridLayoutManager(4, OrientationHelper.VERTICAL));
        recyclerView.setAdapter(photoAdapter);
        /**
         * 为recyclerView设置监听事件
         */
        recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this,
                new RecyclerItemClickListener.OnItemClickListener() {
                    @Override
                    public void onItemClick(View view, int position) {
                        if (photoAdapter.getItemViewType(position) == PhotoAdapter.TYPE_ADD) {
//                            PhotoPicker.builder()
//                                    .setPhotoCount(PhotoAdapter.MAX)
//                                    .setShowCamera(true)
//                                    .setPreviewEnabled(true)
//                                    .setSelected(selectedPhotos)
//                                    .start(CommentActivity.this);
                        } else {
//                            PhotoPreview.builder()
//                                    .setPhotos(selectedPhotos)
//                                    .setCurrentItem(position)
//                                    .start(CommentActivity.this);
                        }
                    }
                }));
        //设置默认星星的数量
//        ratingBarView.setStarMark(3.0f);
        //给星星设置整数评分
        ratingBarView.setIntegerMark(true);
        ratingBarView.setOnStarChangeListener(new RatingBarView.OnStarChangeListener() {
            @Override
            public void onStarChange(float ratingCount) {
                LogUtils.logi("ratingCount",ratingCount);
                comment_tv_des_status.setVisibility(View.VISIBLE);
                String tet = null;
                if(ratingCount == 1.0){
                    tet ="一般";
                }else if(ratingCount == 2.0){
                    tet ="好";
                }else if(ratingCount == 3.0){
                    tet ="很好";
                }else if(ratingCount == 4.0){
                    tet ="非常好";
                }else if(ratingCount == 5.0){
                    tet ="非常棒";
                }else if(ratingCount == 0.0){
                    comment_tv_des_status.setVisibility(View.GONE);
                }
                comment_tv_des_status.setText(tet);

            }
        });



    }

    /**
     * 填充布局文件
     * @return
     */
    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_commit_comment;
    }
    @OnClick(R.id.iv_back_page)
    public void onClickBack(){
        finish();
    }
    @OnClick(R.id.picker_ll_photo)
    public void onClickPickerPhoto(){
//        PhotoPicker.builder()
//                .setPhotoCount(9)
//                .setShowCamera(false)
//                .setShowGif(false)
//                .setPreviewEnabled(false)
//                .start(this,PhotoPicker.REQUEST_CODE);

    }

    /**
     * 回调返回数据
     * @param requestCode
     * @param resultCode
     * @param data
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
//        if (resultCode == RESULT_OK &&
//                (requestCode == PhotoPicker.REQUEST_CODE || requestCode == PhotoPreview.REQUEST_CODE)) {
//
//            List<String> photos = null;
//            if (data != null) {
//                photos = data.getStringArrayListExtra(PhotoPicker.KEY_SELECTED_PHOTOS);
//
//            }
//            selectedPhotos.clear();
//
//            if (photos != null) {
//                selectedPhotos.addAll(photos);
//            }
//            photoAdapter.notifyDataSetChanged();
//        }
    }
}
